package maUtil;


public class CompareByValue implements java.util.Comparator {
	public int compare(Object a, Object b) 
	{
		
		if(a instanceof RecordUnit && b instanceof RecordUnit)
		{
			return compare((RecordUnit) a, (RecordUnit) b);
		}
		else if (a instanceof RecordUnitF && b instanceof RecordUnitF)
		{
			return compare((RecordUnitF) a, (RecordUnitF) b);
		}
		else
			return Integer.MIN_VALUE;
			//throw new Exception("Unexpected type.");
	}
	public int compare(RecordUnit a, RecordUnit b) {
		  int sdif = b.getValue() - a.getValue();
		  return sdif;
		 }
	
	public int compare(RecordUnitF a, RecordUnitF b) {
		  float sdif = b.getValue() - a.getValue();
		  if (sdif < Integer.MIN_VALUE)
			  return Integer.MIN_VALUE;
		  else if(sdif > Integer.MAX_VALUE)
			  return Integer.MAX_VALUE;
		  return (int) sdif;
		 }

}
